package com.zhuangfei.hpuhelper.tools;

import java.io.Serializable;

import cn.lzf.serviceplatform.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.WindowManager;

public class ActivityTools {
	
	//状态栏高度
	private static int statusHeight=-1;
	
	/**
	 * 设置透明状态栏
	 */
	@SuppressLint("InlinedApi")
	public static void setTransparent(Activity activity) {
		if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
			activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		}
	}
	
	/**
	 * 返回Home
	 * @param context
	 */
	public static void toHome(Context context){
		Intent home = new Intent(Intent.ACTION_MAIN);
		home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		home.addCategory(Intent.CATEGORY_HOME);
		context.startActivity(home);
	}
	
	/**
	 * 使用默认的入场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toActivity(Activity context,Class<?> target){
		Intent intent=new Intent(context,target);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	/**
	 * 使用默认的出场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toBackActivityAnim(Activity context,Class<?> target){
		Intent intent=new Intent(context,target);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide_in, R.anim.slide_out);//动画
		context.finish();
	}
	

	public static void toBackActivityAnimByExtras(Activity context,Class<?> target,String key,int value){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide_in, R.anim.slide_out);//动画
		context.finish();
	}
	
	
	

	
	
	/**
	 * 使用默认的入场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toActivityAnimByExtras(Activity context,Class<?> target,String key,String value){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	public static void toActivityAnimByExtras(Activity context,Class<?> target,String key,String value,String key2,int value2){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		intent.putExtra(key2, value2);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	public static void toActivityAnimByExtras(Activity context,Class<?> target,String key,int value){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	/**
	 * 使用默认的入场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toActivityAnimByExtras2(Activity context,Class<?> target,String key,String value,String key2,String value2){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		intent.putExtra(key2, value2);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	public static void toActivityAnimByExtras(Activity context,Class<?> target,String key,String value,String key2,String value2,String key3,int sign){
		Intent intent=new Intent(context,target);
		intent.putExtra(key, value);
		intent.putExtra(key2, value2);
		intent.putExtra(key3, sign);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	/**
	 * 使用默认的入场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toActivityAnimByExtras3(Activity context,Class<?> target,String key,Serializable value,String key2,String value2){
		Intent intent=new Intent(context,target);
		Bundle bundle=new Bundle();
		bundle.putSerializable(key, value);
		bundle.putString(key2, value2);
		intent.putExtras(bundle);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	
	public static void toBackActivityAnimByExtras(Activity context,Class<?> target,String key,Serializable value,String key2,String value2){
		Intent intent=new Intent(context,target);
		Bundle bundle=new Bundle();
		bundle.putSerializable(key, value);
		bundle.putString(key2, value2);
		intent.putExtras(bundle);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide_in, R.anim.slide_out);//动画
		context.finish();
	}
	
	
	/**
	 * 使用默认的入场动画效果
	 * 从context跳转到target页面
	 * @param context
	 * @param target
	 */
	public static void toActivityAnimByExtras(Activity context,Class<?> target,String key,Serializable value){
		Intent intent=new Intent(context,target);
		Bundle bundle=new Bundle();
		bundle.putSerializable(key, value);
		intent.putExtras(bundle);
		context.startActivity(intent);
		context.overridePendingTransition(R.anim.slide2_in, R.anim.slide2_out);//动画
	}
	
	/**
	 * 获取状态栏高度
	 * @param context
	 * @return
	 */
	public static int getStatusHeight(Context context) {
		if(statusHeight!=-1) return statusHeight;
		int statusBarHeight= -1;
		// 获取status_bar_height资源的ID
		int resourceId = context.getResources().getIdentifier("status_bar_height",
				"dimen", "android");
		if (resourceId > 0) {
			// 根据资源ID获取响应的尺寸值
			statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
			statusHeight=statusBarHeight;
		}
		return statusBarHeight;
	}
}
